package com.qfedu.bookstores.controller;

import cn.dsna.util.images.ValidateCode;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/CreateCode")
public class CreateCode extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.创建验证码对象
        ValidateCode validateCode = new ValidateCode(90,30,4,20);
        //2.获取产生的验证码
        String code = validateCode.getCode();
        //3.存在Session对象中让注册servlet进行获取验证
        request.getSession().setAttribute("code", code);
        //4.将验证码响应在页面上
        validateCode.write(response.getOutputStream());
    }
}
